
const baseUrl = 'http://127.0.0.1/jinqi_api/public/index.php/api/';

class HTTP {

    // 封装外层请求;
    request({url,method='get',data={},requireAuth=false}){
        
      return new Promise((resolve, reject)=>{
          this._request({url,method,data,requireAuth,resolve,reject});
      })
         
    }

   // 封装私有方法;
  _request({url, method, data, requireAuth,resolve,reject}){

    let header = { "content-type": "application/json"};
    
    if(requireAuth){
      
      let token = wx.getStorageSync('token');
      header.Authorization = "Bearer " + token;
      
    }
     
    // 真实请求 
    wx.request({
      
      url: baseUrl+url,
      data,
      method,
      header,
      success:res=>{
          resolve(res);
      },
      fail:err=>{
        reject(err);
      }
      
      
    })

        
    }


    checkLogin(){

      let isLogin = wx.getStorageSync('isLogin');

      if (!isLogin) {

        wx.switchTab({
          url: '/pages/about/about'
        })
        
      }
      
    }
    
    
}

export default new HTTP();

